<?php
//接收数据
$staff = array(
    'id' => empty($_POST['id']) ? 0 : $_POST['id'],
    'staffname' => @$_POST['staffname'],
    'age' => @$_POST['age'],
    'wage' => @$_POST['wage'],
    'position' => @$_POST['position'],
    'sex' => @$_POST['sex'],
    'educational' => @$_POST['educational'],
    'time' => @$_POST['time'],
    'phone' => @$_POST['phone'],
);


require 'sql.php';//使用require语句包含并执行sql.php

//添加
if(isset($_POST["addstaff"])) {
    $Msql = "insert into staff (id,staffname,age,wage,position,sex,educational,time,phone) values('{$staff['id']}','{$staff['staffname']}','{$staff['age']}','{$staff['wage']}','{$staff['position']}','{$staff['sex']}','{$staff['educational']}','{$staff['time']}','{$staff['phone']}')";
    $Mresult = mysql_query($Msql);
    if ($Mresult > 0) {
        echo "添加成功";
    } else {
        echo "添加失败";
    }
}
//删除
if(isset($_POST["delstaff"])){
    $id = $_POST['id'];
    $del="delete from staff where Id=$id";
    $resultd= mysql_query($del);
    if($resultd != 0){
        echo  "删除成功";
    }else{
        echo  "删除失败";
    }
}

$add="select id,staffname,age,wage,position,sex,educational,time,phone from staff";//查询遍历
$aresult= mysql_query($add);
while($row=mysql_fetch_row($aresult)){
    $staffl[]=$row;
}

?>